package leetcode.code0798;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution2 implements IDebug {

	public int bestRotation(int[] nums) {
		int n = nums.length;
		int[] help = new int[n];
		for (int i = 0; i < n; i++) {
			int one = n - nums[i];
			help[(i + 1) % n] += 1;
			help[(i + 1 + one) % n] -= 1;
		}
		int ans = 0;
		int max = -1, sum = 0;
		for (int i = 0; i < n; i++) {
			sum += help[i];
			if (sum > max) {
				max = sum;
				ans = i;
			}
		}
		return ans;
	}

	@Override
	public void debug1() {

		HelpDebug.compare(9, this.bestRotation(HelpDebug.str2array3("[6,2,8,3,5,6,7,8,7,6]")));
	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub
		HelpDebug.compare(1, this.bestRotation(HelpDebug.str2array3("[2,2,1,4,2]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub
		HelpDebug.compare(3, this.bestRotation(HelpDebug.str2array3("[2,3,1,4,0]")));

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
